#!/usr/bin/env python
# -*- coding: utf_8 -*-

#    guteninja: a frontend for various video-games
#    Copyright (C) 2007  Tor-björn Claesson

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
import game, gamesystem, interface, os, sys
from config import *


if __name__=="__main__":

    #Skapa en hasch med de olika spelsystemen
    gamesystems = {"native": gamesystem.native(),
                   "dos": gamesystem.dos(),
                   "nes": gamesystem.nes(),
                   "snes": gamesystem.snes()}

    #Spara aktuellt bibliotek i path
    if len(sys.argv) > 1:
        path = (sys.argv[1])
    else:
        path = ("./")

    #Vilka filer finns här?
    alla_filer = os.listdir(path)

    #Vilka av dessa slutar på .spel? Gör spelobjekt av dem och lägg dessa i spellista
    spellista = []
    for i in alla_filer:
    	if i[-5:] == ".spel":
    	    spellista.append(game.game(from_file = i, path=path))
    alla_filer = None
    
    #Vilka filer finns hￃﾤr?
    alla_filer = os.listdir(GAMEDIR)

    #Vilka av dessa slutar pￃﾥ .spel? Gￃﾶr spelobjekt av dem och lￃﾤgg dessa i spellista
    for i in alla_filer:
        if i[-5:] == ".spel":
            spellista.append(game.game(from_file = i, path=GAMEDIR))
    alla_filer = None
    
    #Starta gränssnitt
    spelet = interface.interface(graphical=True, game_list=spellista)
    
    #Loopa genom gränssnittet
    while True:        
        spel = spelet.run()
        #Kör det valda spelet med rätt spelsystem!
        gamesystems[spel.gamesystem].run(game=spel)
